/*  Copyright 2003-2016 Patrick G. Durand
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package part2;

import com.plealog.genericapp.api.EZApplicationBranding;
import com.plealog.genericapp.api.EZEnvironment;
import com.plealog.genericapp.api.EZGenericApplication;
import com.plealog.genericapp.api.EZUIStarterListener;

import javax.swing.*;
import java.awt.*;

public class TutorialTwoUIStarter {
	public static void main(String[] args) {
		// This has to be done at the very beginning, i.e. first method call within main().
		EZGenericApplication.initialize("TutorialTwoUIStarter");
		// Add application branding
		EZApplicationBranding.setAppName("TutorialTwoUIStarter");
		EZApplicationBranding.setAppVersion("1.0");
		EZApplicationBranding.setCopyRight("Created by me");
		EZApplicationBranding.setProviderName("Plealog Software");

		// Add a listener to application startup cycle (see below)
		EZEnvironment.setUIStarterListener(new MyStarterListener());

		// Start the application
		EZGenericApplication.startApplication(args);
	}

	private static class MyStarterListener implements EZUIStarterListener {

		@Override
		public Component getApplicationComponent() {
			// This method is called by the framework to obtain the UI main component to be displayed in the main frame.

			JPanel mainPanel = new JPanel(new BorderLayout());
			JTabbedPane tabPanel = new JTabbedPane();

			tabPanel.add("My First Component", new JPanel());

			mainPanel.add(tabPanel, BorderLayout.CENTER);
			return mainPanel;
		}

		@Override
		public boolean isAboutToQuit() {
			// You can add some code to figure out if application can exit.

			// Return false to prevent application from exiting (e.g. a background
			// task is still running).
			// Return true otherwise.

			// Do not add a Quit dialogue box to ask user confirmation: the framework already does that for you.
			return true;
		}

		@Override
		public void postStart() {
			// This method is called by the framework just before displaying UI
			// (main frame).
		}

		@Override
		public void preStart() {
			// This method is called by the framework at the very beginning of
			// application startup.
		}

		@Override
		public void frameDisplayed() {
		}
	}
}
